import { BaseDeployPanel } from "./BaseDeployPanel";
import { Language } from "../../../../../../extend/language/Language";
import { EBind } from "../../../../../../Message/Public/EBind";
import { ItemData } from "../../../../resource/info/ItemData";
import { ItemConfig } from "../../../../resource/ItemConfig";
import { JSON } from "../../../../../../com/mui/serialization/json/JSON";
import { DataEvent } from "../../../../events/DataEvent";
import { EquipmentModuleConst } from "../../data/EquipmentModuleConst";
import { ECategory } from "../../../../../../Message/Public/ECategory";
import { JewelUtil } from "../../../common/util/JewelUtil";
import { MsgManager } from "../../../../manager/MsgManager";
import { Cache } from "../../../../cache/Cache";
import { Alert } from "../../../../../../com/mui/controls/Alert";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { EProp } from "../../../../../../Message/Public/EProp";
import { PopupManager } from "../../../../manager/PopupManager";
import { EItemUpdateResult } from "../../../../../../Message/Game/EItemUpdateResult";
import { NetDispatcher } from "../../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../../mvc/ServerCommand";
import { EquipUpdateParams } from "../../data/EquipUpdateParams";
import { AutoComposeJewelPanel } from "../../popupPanels/AutoComposeJewelPanel";
import { EventName } from "../../../../mvc/EventName";
import { SPlayerItem } from "../../../../../../Message/Public/SPlayerItem";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { SItemUpdateConsume } from "../../../../../../Message/Game/SItemUpdateConsume";
import { ColorConfig } from "../../../../resource/ColorConfig";
import { GameDefConfig } from "../../../../resource/GameDefConfig";
import { AutoUpdateResultPanel } from "../../popupPanels/AutoUpdateResultPanel";
import { DeployPanelItem } from "../DeployPanelItem";
import { EquipPropButton } from "../EquipPropButton";
import { GImageBitmap } from "../../../../../../com/mui/controls/GImageBitmap";
import { FilterConst } from "../../../../../component/gconst/FilterConst";
import { ObjCreate } from "../../../common/ObjCreate";
import { ComposeJewelChangeBtn } from "./compose/ComposeJewelChangeBtn";
import { ComposeJewelMode } from "./compose/ComposeJewelMode";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GModuleEvent } from "../../../../mvc/GModuleEvent";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { ShopConfig } from "../../../../resource/ShopConfig";
import { TodayNotTipUtil } from "../../../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../../../component/gconst/TodayNoTipsConst";
type int = number;
//class ComposeJewelPanel
    
    export  class ComposeJewelPanel extends BaseDeployPanel
    {
        constructor()
        {
            this.currentJewels = [];
            this.choosedProps = [];
            this.currentJewelType = {"type": null, "level": null};
            this._lastComposeSetting = {};
            this._alarmText = Language.getString(60125);
            this.posData = [{"x": 100, "y": 120, "label":"", "canRemove": true, "noBoarder": true, "isJewel": true}, {"x": 80, "y": 198, "label":"", "canRemove": true, "noBoarder": true, "isJewel": true}, {"x": 230, "y": 198, "label":"", "canRemove": true, "noBoarder": true, "isJewel": true}, {"x": 214, "y": 120, "label":"", "canRemove": true, "noBoarder": true, "isJewel": true}, {"x": 155, "y": 256, "label": Language.getString(60126), "canRemove": true, "noBoarder": true}, {"x": 157, "y": 180, "label":"", "canRemove": true, "noBoarder": false}];
            this.buttonLabel = Language.getString(60127);
            super();
            return;
        }

        /* internal  */checkIsChangeToBind(): Boolean
        {
            var loc3=null;
            var loc1=false;
            var loc2=false;
            var loc4=0;
            while (loc4 <= 3) 
            {
                loc3 = allItem[loc4].itemData;
                if (loc3 && !(loc3.itemInfo.item.bind == EBind._EBindNo)) 
                {
                    loc2 = true;
                }
                else if (loc3 && loc3.itemInfo.item.bind == EBind._EBindNo) 
                {
                    loc1 = true;
                }
                ++loc4;
            }
            if (allItem[4].itemData && !(allItem[4].itemData.itemInfo.item.bind == EBind._EBindNo)) 
            {
                loc2 = true;
            }
            if (loc1 && loc2) 
            {
                return true;
            }
            return false;
        }

        /* internal  */getUpperLevelItemData(arg1: ItemData): ItemData
        {
            var loc1=null;
            if (!arg1) 
            {
                return null;
            }
            if (arg1.itemInfo.item.itemLevel <= 7) 
            {
                loc1 = ItemConfig.instance.getItemInfoByParams(arg1.category, arg1.type, arg1.itemInfo.item.bind, arg1.itemInfo.item.level, -1, arg1.itemInfo.item.itemLevel + 1);
            }
            else 
            {
                loc1 = ItemConfig.instance.getDoubleJewelInfo(arg1, this.secondJewel);
            }
            return loc1 ? new ItemData(loc1.item.code) : null;
        }

        protected /* override */ updateStatus(): void
        {
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc1=0;
            var loc2=this.jewelNum;
            var loc6;
            this._autoBtn.enabled = loc6 = true;
            confirmButton.enabled = loc6;
            if (!this.updateConfigInfo) 
            {
                loc4 = ItemConfig.instance.getUpdateInfo(ItemConfig.ComposeJewel, 1)["condition"];
                this.updateConfigInfo = JSON.deserialize(loc4);
                loc1 = this.updateConfigInfo.cost;
            }
            if (loc2 != 3) 
            {
                if (loc2 != 4) 
                {
                    if (loc2 == 2 && this.firstJewel.itemInfo.item.itemLevel >= 7) 
                    {
                        loc3 = this.updateConfigInfo.rate4;
                    }
                    else 
                    {
                        loc3 = 0;
                    }
                }
                else 
                {
                    loc3 = this.updateConfigInfo.rate4;
                }
            }
            else 
            {
                loc3 = this.updateConfigInfo.rate3;
            }
            if (loc2 > 0 && this.firstJewel && this.firstJewel.itemInfo.item.itemLevel < 8) 
            {
                loc1 = this.updateConfigInfo.cost;
            }
            else if (loc2 > 0 && this.firstJewel && this.firstJewel.itemInfo.item.itemLevel == 8) 
            {
                if (!this.updateConfigInfo2) 
                {
                    loc5 = ItemConfig.instance.getUpdateInfo(ItemConfig.ComposeJewel2Cost, 1)["condition"];
                    this.updateConfigInfo2 = JSON.deserialize(loc5);
                }
                loc1 = this.updateConfigInfo2.cost;
            }
            else 
            {
                loc1 = 0;
            }
            if (loc1 != _cost) 
            {
                _cost = loc1;
                this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_CostChange, _cost, false, true));
            }
            if (this.useProtectPropNum == 1 && allItem[4].itemData && (loc2 >= 3 || loc2 == 2 && this.firstJewel.itemInfo.item.itemLevel >= 7)) 
            {
                loc3 = loc3 + this.updateConfigInfo.add_rate;
            }
            else if (allItem[4].itemData && loc2 < 3) 
            {
                allItem[4].itemData = null;
            }
            if (loc2 >= 3 || loc2 == 2 && this.firstJewel.itemInfo.item.itemLevel >= 7) 
            {
                allItem[5].itemData = this.getUpperLevelItemData(this.firstJewel);
            }
            else 
            {
                allItem[5].itemData = null;
            }
            if (this.useProtectPropNum != 0) 
            {
                this._propBtn.visible = false;
            }
            else 
            {
                this._propBtn.visible = true;
            }
            this.successRate = loc3;
            return;
        }

        /* internal  */onMaterialChange(): void
        {
            var loc1=[];
            var loc2=0;
            while (loc2 < 4) 
            {
                if (allItem[loc2].itemData && allItem[loc2].itemData.category == ECategory._ECategoryJewel) 
                {
                    loc1.push(allItem[loc2].itemData);
                }
                ++loc2;
            }
            this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_ChoosedMaterialChange, loc1, false, true));
            return;
        }

        public /* override */ clear(): void
        {
            _cost = 0;
            this.clearAllItem();
            return;
        }

        public /* override */ putInItem(arg1: ItemData, arg2: Boolean=false, arg3=null): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            if (arg1.itemInfo.item.category == ECategory._ECategoryJewel) 
            {
                if (!JewelUtil.isCanCompose(arg1)) 
                {
                    return;
                }
                if (!(this.currentJewelType.type == arg1.itemInfo.item.type) || !(this.currentJewelType.level == arg1.itemInfo.item.level) || !(this.currentJewelType.itemLevel == arg1.itemInfo.item.itemLevel)) 
                {
                    if (arg1.itemInfo.item.itemLevel <= 7 && (this.currentJewelType.itemLevel <= 7 || arg1.itemInfo.item.itemLevel <= 7)) 
                    {
                        this.clear();
                    }
                    if (arg1.itemInfo.item.itemLevel <= 7) 
                    {
                        this.currentJewelType = {"type": arg1.itemInfo.item.type, "level": arg1.itemInfo.item.level, "itemLevel": arg1.itemInfo.item.itemLevel, "code": arg1.itemInfo.item.code};
                    }
                }
                if (arg1.itemInfo.item.itemLevel == 8) 
                {
                    if (this.firstJewel && this.firstJewel.itemInfo.item.itemLevel < 8) 
                    {
                        this.clear();
                    }
                    this.currentJewelType = {"type": arg1.itemInfo.item.type, "level": arg1.itemInfo.item.level, "itemLevel": arg1.itemInfo.item.itemLevel, "code": arg1.itemInfo.item.code};
                }
                loc3 = arg1.itemAmount;
                loc2 = 0;
                while (loc2 < 4) 
                {
                    if (allItem[loc2].itemData && allItem[loc2].itemData.uid == arg1.uid) 
                    {
                        --loc3;
                    }
                    ++loc2;
                }
                loc4 = 4;
                if (arg1.itemInfo.item.itemLevel >= 7) 
                {
                    loc4 = 2;
                }
                if (arg1.itemInfo.item.itemLevel >= 8) 
                {
                    loc4 = 1;
                }
                loc2 = 0;
                while (loc2 < loc4) 
                {
                    if (loc3 >= 1) 
                    {
                        if (allItem[loc2].itemData != null) 
                        {
                            if (allItem[loc2].itemData.itemInfo.item.itemLevel >= 8) 
                            {
                                allItem[loc2 + 1].itemData = arg1;
                                --loc3;
                            }
                        }
                        else 
                        {
                            allItem[loc2].itemData = arg1;
                            --loc3;
                        }
                    }
                    ++loc2;
                }
                this.onMaterialChange();
            }
            this.updateStatus();
            return;
        }

        /* internal  */onButtonClickImpl(arg1): void
        {
            var target;
            var firstJewel: ItemData;

            var loc1;
            target = arg1;
            firstJewel = this.firstJewel;
            if (!firstJewel) 
            {
                MsgManager.showRollTipsMsg(Language.getString(61084));
                return;
            }
            if (JewelUtil.isNeedSpecialCompose(firstJewel) && this.jewelNum < 2) 
            {
                MsgManager.showRollTipsMsg(Language.getString(61085));
                return;
            }
            if (!JewelUtil.isNeedSpecialCompose(firstJewel) && this.jewelNum < 3) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60129));
                return;
            }
            if (JewelUtil.isNeedSpecialCompose(firstJewel)) 
            {
                if (allItem[2].enabled == false || allItem[3].enabled == false) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(61086));
                    return;
                }
            }
            if (!isEnoughMoney) 
            {
                if (target == confirmButton || target == this._autoBtn) 
                {
                    this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_CoinNotEnough, null, false, true, true));
                }
                MsgManager.showRollTipsMsg(Language.getString(60121));
                return;
            }
            if (this.useProtectPropNum == 1 && allItem[4].itemData && !allItem[4].enabled) 
            {
                if (Cache.instance.equipment.isAutoBuy) 
                {
                    if (target != confirmButton) 
                    {
                    };
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(60130));
                    return;
                }
            }
            var loc2=target;
            switch (loc2) 
            {
                case this._propBtn:
                {
                    this.useProtectPropNum = 1;
                    break;
                }
                case confirmButton: case this._autoBtn:
                {
                    if (firstJewel.itemInfo.item.itemLevel >= 4 && successRate < 100) 
                    {
                        Alert.show("        " + Language.getString(60131), Language.getString(69900), Alert.OK | Alert.CANCEL, null, (arg1: int): void
                        {
                            if (arg1 == Alert.OK) 
                            {
                                doButtonClick(target as GButton);
                            }
                            return;
                        })
                    }
                    else 
                    {
                        this.doButtonClick(target as GButton);
                    }
                    break;
                }
            }
            return;
        }

        public /* override */ setAutoChooseMaterial(arg1: Object): void
        {
            var loc1=arg1.material as Array<any>;
            var loc2=0;
            while (loc2 < 4) 
            {
                if (loc1.length > loc2) 
                {
                    allItem[loc2].itemData = loc1[loc2]["item"];
                    allItem[loc2].enabled = loc1[loc2]["enough"];
                }
                else 
                {
                    allItem[loc2].itemData = null;
                    allItem[loc2].enabled = true;
                }
                ++loc2;
            }
            return;
        }

        public /* override */ setAutoChooseLuckTune(arg1: Object): void
        {
            var loc1=arg1.isEnough;
            this.choosedProps = arg1.luckTune;
            if (this.useProtectPropNum > 0 && this.choosedProps && this.choosedProps.length > 0) 
            {
                allItem[4].itemData = this.choosedProps[0] as ItemData;
                allItem[4].enabled = loc1;
            }
            else 
            {
                allItem[4].itemData = null;
                allItem[4].enabled = true;
            }
            this.updateStatus();
            return;
        }

        public moveOutByIndex(arg1: int): void
        {
            if (allItem[arg1].itemData == null) 
            {
                return;
            }
            if (allItem[arg1].itemData.category == ECategory._ECategoryProp) 
            {
                if (allItem[arg1].itemData.type == EProp._EPropGradeEightJewelCompoMaterial || allItem[arg1].itemData.type == EProp._EPropGradeSpecailJewelCompoMaterial) 
                {
                    return;
                }
            }
            if (arg1 == 4) 
            {
                this.useProtectPropNum = 0;
            }
            allItem[arg1].itemData = null;
            allItem[arg1].enabled = true;
            this.onMaterialChange();
            this.updateStatus();
            return;
        }

        public /* override */ onUpdateResult(arg1: int, arg2: Boolean, arg3, arg4: Array<any>): void
        {
            if (this._autoComposePanel) 
            {
                PopupManager.removePopup(this._autoComposePanel);
            }
            if (arg1 != EItemUpdateResult._EItemUpdateResultSuccess) 
            {
                this.clear();
                MsgManager.showRollTipsMsg(Language.getString(60133));
            }
            else 
            {
                this.clear();
                MsgManager.showRollTipsMsg(Language.getString(60132));
                addUpdateSuccessEffect("equipEffect_composeJewel.swf", 180, 200);
            }
            if (arg2) 
            {
                this.showOperationResult(arg1, arg3, arg4);
            }
            this.updateStatus();
            NetDispatcher.addCmdListener(ServerCommand.StonepackItemsChange, this.serverBagDataChangehandler);
            return;
        }

        /* internal  */serverBagDataChangehandler(arg1: Object): void
        {
            NetDispatcher.removeCmdListener(ServerCommand.StonepackItemsChange, this.serverBagDataChangehandler);
            this.autoUseLastSetting();
            return;
        }

        /* internal  */autoUseLastSetting(arg1: Object /* flash.events.Event */=null): void
        {
            if (allItem[5].itemData) 
            {
                allItem[5].itemData = null;
            }
            this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_ReChooseJewels, this._lastComposeSetting, false, true));
            return;
        }

        /* internal  */onAutoUpdate(arg1: DataEvent): void
        {
            this._autoComposeAmount = arg1.data.amount;
            this.onAutoUpdateImpl(arg1.data.amount, arg1.data.flag);
            return;
        }

        /* internal  */onAutoUpdateImpl(arg1: int, arg2: Boolean): void
        {
            var loc3=null;
            var loc4=null;
            var loc8=0;
            var loc9=null;
            var loc11=null;
            var loc12=null;
            var loc13=null;
            var loc14=null;
            confirmButton.enabled = false;
            this._autoBtn.enabled = false;
            var loc1=[];
            var loc2=0;
            this._lastComposeSetting["firstJewelUid"] = null;
            this._lastComposeSetting["secondJewelUid"] = null;
            var loc5=0;
            while (loc5 < 4) 
            {
                if (allItem[loc5].itemData) 
                {
                    if (allItem[loc5].itemData.itemInfo.item.category == ECategory._ECategoryJewel) 
                    {
                        ++loc2;
                        if (!this._lastComposeSetting["firstJewelUid"]) 
                        {
                            this._lastComposeSetting["firstJewelUid"] = allItem[loc5].itemData.uid;
                            loc3 = allItem[loc5].itemData;
                        }
                        if (allItem[loc5].itemData.itemInfo.item.itemLevel >= 8 && !this._lastComposeSetting["secondJewelUid"]) 
                        {
                            this._lastComposeSetting["secondJewelUid"] = allItem[1].itemData.uid;
                            loc4 = allItem[1].itemData;
                        }
                    }
                }
                ++loc5;
            }
            this._lastComposeSetting["jewelNum"] = loc2;
            this._lastComposeSetting["propData"] = allItem[4].itemData;
            var loc6=Cache.instance.pack.stonePackCache.getJewelItems();
            var loc7=0;
            while (loc7 < loc6.length) 
            {
                loc11 = loc6[loc7] as ItemData;
                if (loc3 && loc11.itemInfo.item.type == loc3.itemInfo.item.type && loc11.itemInfo.item.level == loc3.itemInfo.item.level && loc11.itemInfo.item.itemLevel == loc3.itemInfo.item.itemLevel) 
                {
                    loc1.push(loc11.uid);
                }
                if (loc4 && loc11.itemInfo.item.type == loc4.itemInfo.item.type && loc11.itemInfo.item.level == loc4.itemInfo.item.level && loc11.itemInfo.item.itemLevel == loc4.itemInfo.item.itemLevel) 
                {
                    loc1.push(loc11.uid);
                }
                ++loc7;
            }
            if (loc2 > 0 && JewelUtil.isNeedSpecialCompose(loc3)) 
            {
                loc12 = [];
                if (JewelUtil.isNormalJewel(loc3)) 
                {
                    loc12 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropGradeEightJewelCompoMaterial);
                }
                else if (loc3.itemInfo.item.itemLevel <= 7) 
                {
                    loc12 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropGradeSpecailJewelCompoMaterial);
                }
                else 
                {
                    loc12 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropGradeDoubleJewelCompoMaterial);
                }
                loc12.sortOn("bind", Array.DESCENDING);
                var loc15=0;
                var loc16=loc12;
                for(loc13 of loc16) 
                {
                    if (loc13.itemInfo.item.itemLevel != this.firstJewel.itemInfo.item.itemLevel) 
                    {
                        continue;
                    }
                    loc1.push(loc13.uid);
                }
            }
            var loc10=loc2 * 10000;
            if (allItem[4].itemData && allItem[4].enabled) 
            {
                loc10 = loc10 + 1;
                loc15 = 0;
                loc16 = this.choosedProps;
                for(loc9 of loc16) 
                {
                    loc1.push(loc9.uid);
                    loc8 = loc8 + loc9.itemAmount;
                }
            }
            if (allItem[4].itemData && Cache.instance.equipment.isAutoBuy && loc8 < arg1 && !arg2) 
            {
                if (allItem[4].itemData.itemInfo.item.bind != EBind._EBindYes) 
                {
                    loc9 = allItem[4].itemData;
                }
                else 
                {
                    loc9 = new ItemData(allItem[4].itemData.itemInfo.item.codeUnbind);
                }
                this.autoBuyMaterial(loc9, this._autoBtn, arg1 - loc8);
            }
            else 
            {
                (loc14 = new EquipUpdateParams()).operationId = this.operationId;
                loc14.autoUpdate = true;
                loc14.materials = loc1;
                loc14.target = arg1;
                loc14.num = loc10;
                loc14.flag = arg2;
                this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_DoUpdateEvent1, loc14, false, true));
            }
            return;
        }

        public get autoComposePanel(): AutoComposeJewelPanel
        {
            if (!this._autoComposePanel) 
            {
                this._autoComposePanel = new AutoComposeJewelPanel();
                this._autoComposePanel.addEventListener(EventName.Equipment_OnAutoUpdate, this.onAutoUpdate);
            }
            return this._autoComposePanel;
        }

        /* internal  */showOperationResult(arg1: int, arg2: SPlayerItem, arg3: Array<any>): void
        {
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc1="";
            var loc10=arg1;
            switch (loc10) 
            {
                case EItemUpdateResult._EItemUpdateResultSuccess:
                {
                    loc1 = loc1 + HTMLUtil.addColor(Language.getString(60134), "#ffba00");
                    break;
                }
                case EItemUpdateResult._EItemUpdateResultFail:
                {
                    loc1 = loc1 + HTMLUtil.addColor(Language.getString(60135), "#00FF00");
                    break;
                }
                case EItemUpdateResult._EItemUpdateResultLackCoin:
                {
                    loc1 = loc1 + HTMLUtil.addColor(Language.getString(60136), "#00FF00");
                    break;
                }
                case EItemUpdateResult._EItemUpdateResultLackProtectProp:
                {
                    loc1 = loc1 + HTMLUtil.addColor(Language.getString(60137), "#00FF00");
                    break;
                }
            }
            loc1 = loc1 + "\n";
            var loc2=arg3[0] as SItemUpdateConsume;
            var loc3=Math.floor(loc2.extend / 10000);
            var loc4=loc2.extend % 10000;
            var loc5;
            if (loc5 = ItemConfig.instance.getInfoByCode(arg2.itemCode)) 
            {
                loc1 = loc1 + Language.getStringByParam(60138, HTMLUtil.addColor(String(loc3), "#ff0000"), HTMLUtil.addColor(loc5.item.name, ColorConfig.instance.getItemColorString(loc5.item.color)), HTMLUtil.addColor(String(loc4), "#ff0000"));
            }
            else 
            {
                loc1 = loc1 + Language.getStringByParam(60138, "0", Language.getString(60139), HTMLUtil.addColor(String(loc2.extend), "#ff0000"));
            }
            loc1 = (loc1 = loc1 + "\n") + HTMLUtil.addColor(Language.getString(60140), "#b1efff");
            var loc6=new Map<any, any> /* flash.utils.Dictionary */();
            loc10 = 0;
            var loc11=loc2.itemCodeAmountDict;
            for (loc7 in loc11) 
            {
                loc9 = ItemConfig.instance.getInfoByCode(int(loc7)).item.name;
                if (loc6[loc9]) 
                {
                    loc6[loc9]["count"] = loc6[loc9]["count"] + loc2.itemCodeAmountDict[loc7];
                    continue;
                }
                loc6[loc9] = {"count": loc2.itemCodeAmountDict[loc7], "code": int(loc7)};
            }
            loc10 = 0;
            loc11 = loc6;
            for (loc7 in loc11) 
            {
                loc1 = loc1 + (HTMLUtil.addColor(loc6[loc7]["count"], "#ff0000") + HTMLUtil.addColor(Language.getString(60141), "#b1efff") + HTMLUtil.addColor(loc7, ColorConfig.instance.getItemColorString(ItemConfig.instance.getInfoByCode(loc6[loc7]["code"]).item.color)) + HTMLUtil.addColor("，", "#b1efff"));
            }
            loc1 = loc1 + (HTMLUtil.addColor(Language.getString(60142), "#b1efff") + HTMLUtil.addColor(String(loc2.cost), "#ff0000") + HTMLUtil.addColor(GameDefConfig.instance.getEPrictUnitName(loc2.unit), "#b1efff") + HTMLUtil.addColor("。", "#b1efff"));
            (loc8 = new AutoUpdateResultPanel()).setResultText(loc1, Language.getString(60143));
            PopupManager.addPopUp(loc8, "", true);
            return;
        }

        public get useProtectPropNum(): int
        {
            return this._useProtectPropNum;
        }

        public set useProtectPropNum(arg1: int)
        {
            this._useProtectPropNum = arg1;
            this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_LuckTuneNumChange, arg1, false, true, false));
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc4=null;
            var loc5=null;
            super.createChildren();
            var loc1=0;
            while (loc1 < this.posData.length) 
            {
                loc4 = this.posData[loc1];
                (loc5 = new DeployPanelItem(loc1, loc4.noBoarder, loc4.isJewel)).posIndex = loc1;
                loc5.x = loc4["x"];
                loc5.y = loc4["y"];
                loc5.label = loc4["label"];
                if (loc4.canRemove) 
                {
                    loc5.mouseEnabled = true;
                    loc5.addEventListener(flash.events.MouseEvent.CLICK, this.onItemDoubleClick);
                }
                addChild(loc5);
                allItem.push(loc5);
                ++loc1;
            }
            addChild(allItem[4]);
            addChild(allItem[0]);
            addChild(allItem[5]);
            addChild(allItem[3]);
            addChild(allItem[1]);
            addChild(allItem[2]);
            this._propBtn = new EquipPropButton(Language.getString(60126));
            this._propBtn.x = allItem[4].x + 1;
            this._propBtn.y = allItem[4].y + 1;
            this.addChild(this._propBtn);
            this._propBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            var loc2=new GImageBitmap("equipment_successRate.png");
            loc2.x = 117;
            loc2.y = 83;
            successRateItem.addChild(loc2);
            addChild(successRateItem);
            confirmButton.label = this.buttonLabel;
            confirmButton.x = 68;
            confirmButton.y = 306;
            confirmButton.setSize(75, 26);
            confirmButton.styleName = "ButtonSpecial";
            confirmButton.textField.filters = [FilterConst.glowFilter];
            addChild(confirmButton);
            confirmButton.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._autoBtn = ObjCreate.createGButton(Language.getString(60128), 216, 306, 75, 26, this, "ButtonSpecial");
            this._autoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._changeModeBtn = new ComposeJewelChangeBtn(ComposeJewelMode.ModeNormal);
            this._changeModeBtn.x = 20;
            this._changeModeBtn.y = 64;
            this._changeModeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onChangeModeBtnClick);
            this.addChild(this._changeModeBtn);
            var loc3=ObjCreate.createTextField("", 235, 70, 130, 20, this);
            loc3.htmlText = HTMLUtil.addLink(Language.getString(61111), GlobalStyle.color5);
            loc3.toolTipData = Language.getString(61112);
            return;
        }

        /* internal  */onChangeModeBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.ComposeJewelModeChange));
            return;
        }

        /* internal  */get jewelNum(): int
        {
            var loc1=0;
            var loc2=0;
            while (loc2 < 4) 
            {
                if (allItem[loc2].itemData && allItem[loc2].itemData.category == ECategory._ECategoryJewel) 
                {
                    loc1 = loc1 + 1;
                }
                ++loc2;
            }
            return loc1;
        }

        /* internal  */get firstJewel(): ItemData
        {
            var loc1=0;
            while (loc1 < 4) 
            {
                if (allItem[loc1].itemData) 
                {
                    return allItem[loc1].itemData;
                }
                ++loc1;
            }
            return null;
        }

        /* internal  */get secondJewel(): ItemData
        {
            if (allItem[1].itemData) 
            {
                return allItem[1].itemData;
            }
            return null;
        }

        /* internal  */get materialUidList(): Array<any>
        {
            var loc1=[];
            var loc2=0;
            while (loc2 < 5) 
            {
                if (allItem[loc2].itemData && !(allItem[loc2].itemData.uid == null)) 
                {
                    loc1.push(allItem[loc2].itemData.uid);
                }
                ++loc2;
            }
            return loc1;
        }

        /* internal  */onItemDoubleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as DeployPanelItem;
            this.moveOutByIndex(loc1.posIndex);
            Dispatcher.dispatchEvent(new DataEvent(EventName.RemoveJewelAfter, allItem[0]));
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.onButtonClickImpl(arg1.currentTarget);
            return;
        }

        public /* override */ clearAllItem(): void
        {
            var loc1=0;
            while (loc1 < 5) 
            {
                allItem[loc1].itemData = null;
                allItem[loc1].enabled = true;
                ++loc1;
            }
            this.updateStatus();
            this.currentJewelType = {"type": null, "level": null, "itemLevel": null, "code": null};
            return;
        }

        /* internal  */autoBuyMaterial(arg1: ItemData, arg2, arg3: int=1): void
        {
            var loc1=ShopConfig.instance.getShopItemInfoByCode(arg1.itemCode);
            if (arg2 != confirmButton) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, {"shopItemInfo": loc1, "amount": arg3, "callBack": this.onItemBuySuccessAuto}));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, {"shopItemInfo": loc1, "amount": arg3, "callBack": this.onItemBuySuccess}));
            }
            flash.utils.setTimeout(this.onBuyItemTimeOut, 500);
            return;
        }

        /* internal  */onBuyItemTimeOut(): void
        {
            confirmButton.enabled = true;
            this._autoBtn.enabled = true;
            return;
        }

        /* internal  */onItemBuySuccess(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.bagDataChangehandler);
            return;
        }

        /* internal  */onItemBuySuccessAuto(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.bagDataChangehandlerAuto);
            return;
        }

        /* internal  */bagDataChangehandler(arg1): void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.bagDataChangehandler);
            this.onMaterialChange();
            this.onButtonClickImpl(confirmButton);
            return;
        }

        /* internal  */bagDataChangehandlerAuto(arg1): void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.bagDataChangehandlerAuto);
            this.onMaterialChange();
            this.onAutoUpdateImpl(this._autoComposeAmount, false);
            return;
        }

        /* internal  */doButtonClick(arg1: GButton): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case confirmButton:
                {
                    if (this.checkIsChangeToBind()) 
                    {
                        TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.JewelComposeBindNoTips, this.onConfirmButtonClick, this._alarmText, null, Alert.OK | Alert.CANCEL);
                    }
                    else 
                    {
                        this.onConfirmButtonClick();
                    }
                    break;
                }
                case this._autoBtn:
                {
                    if (this.checkIsChangeToBind()) 
                    {
                        Alert.show(this._alarmText, null, Alert.OK | Alert.CANCEL, null, this.closeAutoConfirmAlert);
                    }
                    else 
                    {
                        this.onAutoConfirmButtonClick();
                    }
                    break;
                }
            }
            return;
        }

        /* internal  */closeAutoConfirmAlert(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                this.onAutoConfirmButtonClick();
            }
            return;
        }

        /* internal  */onConfirmButtonClick(): void
        {
            confirmButton.enabled = false;
            this._autoBtn.enabled = false;
            var loc1=this.jewelNum;
            var loc2=this.firstJewel;
            var loc3=this.secondJewel;
            if (loc2) 
            {
                this._lastComposeSetting["firstJewelUid"] = loc2.uid;
            }
            else 
            {
                this._lastComposeSetting["firstJewelUid"] = null;
            }
            if (loc3) 
            {
                this._lastComposeSetting["secondJewelUid"] = loc3.uid;
            }
            else 
            {
                this._lastComposeSetting["secondJewelUid"] = null;
            }
            this._lastComposeSetting["jewelNum"] = loc1;
            this._lastComposeSetting["propData"] = allItem[4].itemData;
            var loc4=loc1 * 10000;
            if (allItem[4].itemData && (allItem[4].enabled || Cache.instance.equipment.isAutoBuy)) 
            {
                loc4 = loc4 + 1;
            }
            var loc5;
            (loc5 = new EquipUpdateParams()).operationId = this.operationId;
            loc5.materials = this.materialUidList;
            loc5.target = -1;
            loc5.num = loc4;
            loc5.flag = false;
            loc5.autoBuyTone = Cache.instance.equipment.isAutoBuy;
            this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_DoUpdateEvent1, loc5, false, true));
            return;
        }

        /* internal  */onAutoConfirmButtonClick(): void
        {
            var loc8=null;
            var loc9=0;
            var loc10=null;
            var loc11=null;
            var loc1=this.jewelNum;
            var loc2=this.firstJewel;
            var loc3=this.secondJewel;
            var loc4=0;
            var loc5=0;
            var loc6=Cache.instance.pack.stonePackCache.getJewelItems();
            var loc7=0;
            while (loc7 < loc6.length) 
            {
                loc8 = loc6[loc7] as ItemData;
                if (loc2 && loc8.type == loc2.type && loc8.itemInfo.item.level == loc2.itemInfo.item.level && loc8.itemInfo.item.itemLevel == loc2.itemInfo.item.itemLevel) 
                {
                    loc4 = loc4 + loc8.itemAmount;
                }
                if (loc3 && loc8.type == loc3.type && loc8.itemInfo.item.level == loc3.itemInfo.item.level && loc8.itemInfo.item.itemLevel == loc3.itemInfo.item.itemLevel) 
                {
                    loc5 = loc5 + loc8.itemAmount;
                }
                ++loc7;
            }
            loc4 = Math.min(loc4, loc5);
            if (loc2 && JewelUtil.isNeedSpecialCompose(loc2)) 
            {
                loc10 = [];
                if (JewelUtil.isNormalJewel(loc2)) 
                {
                    loc10 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropGradeEightJewelCompoMaterial);
                }
                else if (loc2.itemInfo.item.itemLevel <= 7) 
                {
                    loc10 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropGradeSpecailJewelCompoMaterial);
                }
                else 
                {
                    loc10 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropGradeDoubleJewelCompoMaterial);
                }
                var loc12=0;
                var loc13=loc10;
                for(loc11 of loc13) 
                {
                    if (loc11.itemInfo.item.itemLevel != loc2.itemInfo.item.itemLevel) 
                    {
                        continue;
                    }
                    loc9 = loc9 + loc11.itemAmount;
                }
                loc4 = Math.min(loc4, loc9);
            }
            PopupManager.addPopUp(this.autoComposePanel, "window", true);
            this.autoComposePanel.imageItemData = this.getUpperLevelItemData(loc2);
            if (loc2.itemInfo.item.itemLevel <= 7) 
            {
                this.autoComposePanel.setAmount(Math.floor(loc4 / loc1));
            }
            else 
            {
                loc4 = Math.min(loc4, loc9 / 2);
                this.autoComposePanel.setAmount(loc4);
            }
            return;
        }

        /* internal */ /* var */operationId: int=5;

        /* internal */ /* var */currentJewels: Array<any>;

        /* internal */ /* var */choosedProps: Array<any>;

        /* internal */ /* var */currentJewelType: Object;

        /* internal */ /* var */_delayTimer: Object /* flash.utils.Timer */;

        /* internal */ /* var */_lastComposeSetting: Object;

        /* internal */ /* var */posData: Array<any>;

        /* internal */ /* var */buttonLabel: string;

        /* internal */ /* var */updateConfigInfo: Object;

        /* internal */ /* var */updateConfigInfo2: Object;

        /* internal */ /* var */_propBtn: EquipPropButton;

        /* internal */ /* var */_autoBtn: GButton;

        /* internal */ /* var */_changeModeBtn: ComposeJewelChangeBtn;

        /* internal */ /* var */_autoComposePanel: AutoComposeJewelPanel;

        /* internal */ /* var */_useProtectPropNum: int=1;

        /* internal */ /* var */_alarmText: string;

        /* internal */ /* var */_autoComposeAmount: int;
    }
